package work02.shop;

import org.junit.Assert;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.*;

/**
 * @author sunlggggg
 * @date 2017/4/16
 */
public class ShopCarTest {
    @Test
    public void getAmount() throws Exception {
        ShopCar shopCar = new ShopCar(10);
        Assert.assertEquals(shopCar.getAmount(), 10);
    }

    @Test
    public void addCommodityAmountCase1() throws Exception {
        ShopCar shopCar = new ShopCar(10);
        try {
            shopCar.addCommodityAmount(91);
            fail("Should have thrown an Exception because Stack is Full! ");
        } catch (CarFullException e) {
            assertThat(e.getMessage(), containsString("this car is full"));
        }
    }


    @Test
    public void addCommodityAmountCase2() throws Exception {
        ShopCar shopCar = new ShopCar(10);
        shopCar.addCommodityAmount(90);
        Assert.assertEquals(shopCar.getAmount(), 100);
    }

    @Test
    public void removeCommodityAmountCase1() throws Exception {
        ShopCar shopCar = new ShopCar(10);
        try {
            shopCar.removeCommodityAmount(11);
            fail("Should have thrown an Exception because Stack is empty! ");
        } catch (CarEmptyException e) {
            assertThat(e.getMessage(), containsString("this car is empty"));
        }
    }


    @Test
    public void removeCommodityAmountCase2() throws Exception {
        ShopCar shopCar = new ShopCar(10);
        shopCar.removeCommodityAmount(10);
        Assert.assertEquals(shopCar.getAmount(), 0);
    }


}